package mybatis.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class mybatis2 {

    public String selectuserid(String name) throws SQLException {
        String userid=null;
        Connection con = null;
        PreparedStatement ps = null;
        java.sql.ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/bookstore","root","991010");
            String sql = "SELECT * FROM users WHERE product_name=?";
            ps = con.prepareStatement(sql);
            ps.setString(1,name);
            rs = ps.executeQuery();
            while (rs.next()) {
                userid=rs.getString(1);
                return userid;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (con != null) {
                con.close();
            }
            if (ps != null) {
                ps.close();
            }
        }
        return userid;
    }
}
